<?php
/**
 * The controller to manage information of medicine.
 *
 */
class C_Career extends Controller {

	public $template_mod;

	function C_Career($template_mod = "general") {
		parent::Controller();
		if (Celini::getCurrentController() == 'Career') {
			$menu =& Menu::getInstance();
			$menu->currentSection = 'admin';
		}
		$this->template_mod = $template_mod;
		$this->view->path = 'career';
		$this->setLayout('admin');
	}

	public function actionManagement() {
		return $this->view->render('management.html');
	}

	public function actionList() {
		$list = Celini::newORDO("Career") -> getCareerList();
		$this->assign('list', $list);

		return $this->view->render('list.html');

	}

	public function actionEdit() {
		$id = $_GET['service_id'];
		$career = Celini::newORDO('Career');

		if (isset($id) && $id != "") {
			$career->setup($id);
		}
		$this->assign_by_ref('career', $career);
		return $this->view->render('edit.html');

	}

	public function actionSaveAjax() {
		$field		=	L10nHelper::getLocale();
		$field      =   L10nHelper::changeField($field, "name");
		$career = Celini::newORDO('Career');
		if (isset($_POST['id']) && $_POST['id'] != 0) {
			//edit
			$data = array($field => Utils::sanitizeText($_POST['name']));
			$career->setup($_POST['id']);

		} else {
			//addnew to all supported languages
			$locales = L10nHelper::getSupportedLocales();
			$data = array();
			foreach ( $locales as $lo => $la ) {
				$lo = L10nHelper::changeField($lo, "name");
				$data[$lo] = Utils::sanitizeText($_POST['name']);
			}
		}
		$data['auto_suggest_code']	= $_POST['code'];
		$career->populateArray($data);
		$career->persist();
		return $career->get_id();
	}

	public function actionChangeStatusAjax() {
		$status = $_GET['status'];
		$id = $_GET['id'];
		$career = Celini::newORDO('Career', $id);
		if($status == 'lock'){
			$res = $career->disableCareer($id);
		}
		else if($status == 'unlock'){
			$res = $career->enableCareer($id);
		}
	}


}
?>